package com.ruoyi.web.controller.qiushi.user;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.user.MemberFamily;
import com.ruoyi.qiushi.service.user.IMemberFamilyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户家人Controller
 *
 * @author ruoyi
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/qiushi/user/memberfamily")
public class MemberFamilyController extends BaseController {
    @Autowired
    private IMemberFamilyService memberFamilyService;

    /**
     * 查询用户家人列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:user:memberfamily:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberFamily memberFamily) {
        startPage();
        List<MemberFamily> list = memberFamilyService.selectMemberFamilyList(memberFamily);
        return getDataTable(list);
    }

    /**
     * 导出用户家人列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:user:memberfamily:export')")
    @Log(title = "用户家人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberFamily memberFamily) {
        List<MemberFamily> list = memberFamilyService.selectMemberFamilyList(memberFamily);
        ExcelUtil<MemberFamily> util = new ExcelUtil<MemberFamily>(MemberFamily.class);
        util.exportExcel(response, list, "用户家人数据");
    }

    /**
     * 获取用户家人详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:user:memberfamily:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(memberFamilyService.selectMemberFamilyById(id));
    }

    /**
     * 新增用户家人
     */
    @PreAuthorize("@ss.hasPermi('qiushi:user:memberfamily:add')")
    @Log(title = "用户家人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberFamily memberFamily) {
        return toAjax(memberFamilyService.insertMemberFamily(memberFamily));
    }

    /**
     * 修改用户家人
     */
    @PreAuthorize("@ss.hasPermi('qiushi:user:memberfamily:edit')")
    @Log(title = "用户家人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberFamily memberFamily) {
        return toAjax(memberFamilyService.updateMemberFamily(memberFamily));
    }

    /**
     * 删除用户家人
     */
    @PreAuthorize("@ss.hasPermi('qiushi:user:memberfamily:remove')")
    @Log(title = "用户家人", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(memberFamilyService.deleteMemberFamilyById(id));
    }
}
